<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateOauthClientsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up() {
        $table = $this->table('oauth_clients', ['engine' => 'innodb', 'collation' => 'utf8mb4_unicode_ci', 'comment' => 'oauth 应用表']);
        $table->addColumn('user_id', 'biginteger', ['limit' => 20, 'signed' => false, 'null' => false, 'comment' => '用户id']);
        $table->addColumn('name', 'string', ['limit' => 255, 'null' => false, 'comment' => '应用名称']);
        $table->addColumn('secret', 'string', ['limit' => 255, 'null' => true, 'comment' => '应用秘钥']);
        $table->addColumn('provider', 'string', ['limit' => 255, 'null' => true, 'comment' => '提供者']);
        $table->addColumn('redirect', 'text', ['comment' => '跳转链接']);
        $table->addColumn('revoked', 'boolean', ['signed' => false, 'default' => 0, 'comment' => '0:撤销 1:未撤销']);
        $table->addColumn('created_at', 'datetime', ['comment' => '创建时间', 'null' => true]);
        $table->addColumn('updated_at', 'datetime', ['comment' => '更新时间', 'null' => true]);

        $table->addIndex('user_id');
        $table->create();
    }

    public function down() {
        $this->table('oauth_clients')->drop();
    }
}
